﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Vds2465Telegrams;

namespace Vds2465Control
{
	internal static class TelegramHelper
	{
		/// <summary>
		/// Check if the given telegram has a user data collection and return this in the positive scenario
		/// </summary>
		/// <param name="telegram"></param>
		/// <param name="userDataColl"></param>
		/// <returns></returns>
		internal static bool GetUserDataColl(Telegram telegram, out UserDataColl userDataColl)
		{
			userDataColl = null;

			if (
					(telegram is Telegram_Calling_SEND_NDAT)
				||	(telegram is Telegram_Returning_VariableLength)	// Telegram_Returning_CONFIRM_ACK and Telegram_Returning_RESPOND_NDAT
				)
			{
				// check the user data
				if (telegram is Telegram_Calling_SEND_NDAT)
				{
					Telegram_Calling_SEND_NDAT telegramCallingSendNdat = telegram as Telegram_Calling_SEND_NDAT;
					userDataColl = telegramCallingSendNdat.GetCopyOfUserDataColl();
					return true;
				}

				Telegram_Returning_VariableLength telegramReturningVariableLength = telegram as Telegram_Returning_VariableLength;
				userDataColl = telegramReturningVariableLength.GetCopyOfUserDataColl();
				return true;
			}

			return false;
		}
	}
}
